package com.youdianstar.app.common.bind.viewadapter.imageview;


import android.widget.ImageView;

import androidx.databinding.BindingAdapter;

import com.youdianstar.app.common.R;

/**
 * File: ViewAdapter
 * author: zhangjiabiao Create on 2020/5/6 10:29
 * Change (from 2020/5/6)
 * --------------------------------
 * description:
 * ----------------------------
 */
public class ViewAdapter {

    /****************************************换肤根据配置加载资源***************************************************/

    /**
     * 设置背景颜色
     *
     * @param view 目标控件
     * @param res 默认资源
     * @param tag 额外配置标签,可以通过代码替换资源
     */
    @BindingAdapter(value = {"imageSrc","tag"}, requireAll = false)
    public static void setImageResource(ImageView view, int res, String tag){
        if (res!=0)
            view.setImageResource(res);
    }

    /**
     * 设置背景颜色
     *
     * @param view 目标控件
     * @param res 默认资源
     * @param tagBg 额外配置标签,可以通过代码替换资源
     */
    @BindingAdapter(value = {"imageBg","tagBg"}, requireAll = false)
    public static void setImageBgResource(ImageView view, int res, String tagBg){
        if (res!=0)
            view.setBackgroundResource(res);
    }
}
